package com.cndw.kungfu.model.siege.domain;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.cndw.commons.util.BlankUtils;
import com.cndw.kungfu.config.ConstantsConfig;
import com.cndw.kungfu.domain.GoodsMode;
import com.cndw.kungfu.ext.XmlProcesser;
import com.cndw.kungfu.model.Context;

/**
 * 围城奖励
 * 
 * @author <a href="mailto:whz-work@163.com">汪洪州</a>
 * 
 * @since 1.0 Create on 2012-2-22
 */
public class SiegeAwards {

	public static final String JOIN_E = "1"; // 参与经验
	public static final String JOIN_A = "2"; // 参与银两
	public static final String JOIN_C = "3"; // 参与贡献度
	public static final String TOPTEN_E = "4"; // 帮派前十经验
	public static final String TOPTEN_A = "5"; // 帮派前十银两
	public static final String TOPTEN_C = "6"; // 帮派前十贡献度
	public static final String WARD_E = "7"; // 守城经验
	public static final String WARD_A = "8"; // 守城银两
	public static final String WARD_C = "9"; // 守城贡献度
	public static final String FIRST_TOPTEN = "10"; // 帮派第一的积分前十奖励
	public static final String SECOND_TOPFIFTH = "11"; // 帮派第二的积分前五奖励
	public static final String THIRD_TOPTHIRD = "12"; // 帮派第三的积分前三奖励
	public static final String WARD_TOPTEN = "13"; // 守城奖励
	public static final String JOIN_G = "14"; // 参与者物品奖励

	private String id;
	private String title;
	private String value1;
	private String value10;
	private String value20;
	private String value30;
	private String value40;
	private String value50;
	private String value60;
	private String value70;
	private String value80;
	private String value90;
	private String value100;
	private String value110;
	private String goods;
	private String orangeBoxCount;

	private List<Integer[]> goodsList = new ArrayList<Integer[]>();
	private Map<Integer, Integer> awards = new HashMap<Integer, Integer>(120);

	private static final Map<String, SiegeAwards> siegeAwards = new HashMap<String, SiegeAwards>();

	static {
		load();
	}

	public static synchronized void load() {
		if (siegeAwards.isEmpty()) {
			String fileName = ConstantsConfig.getLocaleResource() + "siegeAwords.xml";
			List<String> value = new ArrayList<String>(100);
			List<SiegeAwards> awardList = XmlProcesser.processXml(SiegeAwards.class, fileName);
			for (SiegeAwards award : awardList) {

				if (BlankUtils.isBlank(award.getGoods())) {
					value.clear();
					value.addAll(Arrays.asList(award.getValue1().split(",")));
					value.addAll(Arrays.asList(award.getValue10().split(",")));
					value.addAll(Arrays.asList(award.getValue20().split(",")));
					value.addAll(Arrays.asList(award.getValue30().split(",")));
					value.addAll(Arrays.asList(award.getValue40().split(",")));
					value.addAll(Arrays.asList(award.getValue50().split(",")));
					value.addAll(Arrays.asList(award.getValue60().split(",")));
					value.addAll(Arrays.asList(award.getValue70().split(",")));
					value.addAll(Arrays.asList(award.getValue80().split(",")));
					value.addAll(Arrays.asList(award.getValue90().split(",")));
					value.addAll(Arrays.asList(award.getValue100().split(",")));
					value.addAll(Arrays.asList(award.getValue110().split(",")));
					for (int i = 0; i < 120; i++) {
						award.getAwards().put(i + 1, Integer.valueOf(value.get(i)));
					}
				} else {
					for (String g : award.getGoods().split(",")) {
						String[] t = g.split("\\*");
						award.getGoodsList().add(new Integer[] { Integer.valueOf(t[0]), Integer.valueOf(t[1]), Integer.valueOf(t[2]) });
					}
				}

				siegeAwards.put(award.getId(), award);
			}
		}
	}

	public static synchronized void updateConfig() {
		siegeAwards.clear();
		load();
	}

	public static SiegeAwards get(String id) {
		return siegeAwards.get(id);
	}

	public static int getValue(String id, Integer level) {
		return siegeAwards.get(id).getAwards().get(level);
	}

	/**
	 * 根据等级获取橙色宝箱
	 * 
	 * @param level
	 * @return
	 */
	public static GoodsMode getOrangeBox(long level) {
		if (level >= 100) {
			return Context.getGoodsServer().getModeById(188077);
		} else if (level >= 80) {
			return Context.getGoodsServer().getModeById(188076);
		} else if (level >= 60) {
			return Context.getGoodsServer().getModeById(188075);
		} else if (level >= 40) {
			return Context.getGoodsServer().getModeById(188074);
		} else if (level >= 30) {
			return Context.getGoodsServer().getModeById(188073);
		} else {
			return Context.getGoodsServer().getModeById(188072);
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getValue1() {
		return value1;
	}

	public void setValue1(String value1) {
		this.value1 = value1;
	}

	public String getValue10() {
		return value10;
	}

	public void setValue10(String value10) {
		this.value10 = value10;
	}

	public String getValue20() {
		return value20;
	}

	public void setValue20(String value20) {
		this.value20 = value20;
	}

	public String getValue30() {
		return value30;
	}

	public void setValue30(String value30) {
		this.value30 = value30;
	}

	public String getValue40() {
		return value40;
	}

	public void setValue40(String value40) {
		this.value40 = value40;
	}

	public String getValue50() {
		return value50;
	}

	public void setValue50(String value50) {
		this.value50 = value50;
	}

	public String getValue60() {
		return value60;
	}

	public void setValue60(String value60) {
		this.value60 = value60;
	}

	public String getValue70() {
		return value70;
	}

	public void setValue70(String value70) {
		this.value70 = value70;
	}

	public String getValue80() {
		return value80;
	}

	public void setValue80(String value80) {
		this.value80 = value80;
	}

	public String getValue90() {
		return value90;
	}

	public void setValue90(String value90) {
		this.value90 = value90;
	}

	public String getGoods() {
		return goods;
	}

	public void setGoods(String goods) {
		this.goods = goods;
	}

	public List<Integer[]> getGoodsList() {
		return goodsList;
	}

	public void setGoodsList(List<Integer[]> goodsList) {
		this.goodsList = goodsList;
	}

	public Map<Integer, Integer> getAwards() {
		return awards;
	}

	public void setAwards(Map<Integer, Integer> awards) {
		this.awards = awards;
	}

	public String getOrangeBoxCount() {
		return orangeBoxCount;
	}

	public void setOrangeBoxCount(String orangeBoxCount) {
		this.orangeBoxCount = orangeBoxCount;
	}

	public String getValue100() {
		return value100;
	}

	public void setValue100(String value100) {
		this.value100 = value100;
	}

	public String getValue110() {
		return value110;
	}

	public void setValue110(String value110) {
		this.value110 = value110;
	}
}
